// Created by amoylel on 18/12/2018.
// Copyright (c) 2018 amoylel All rights reserved.

#ifndef AMO_ANY_VECTOR_8B50A677_D675_474A_B606_A4832AC1510F_HPP__
#define AMO_ANY_VECTOR_8B50A677_D675_474A_B606_A4832AC1510F_HPP__

#include <string>
#include <vector>
#include <amo/json.hpp>
#include <amo/any/any_type_traits.hpp>
#include <amo/any/any.hpp>

namespace amo {
    template<> struct any_value_type<std::vector<any> > {
        static const char value = 42;
    };
    
    template<> std::vector<any> string_to_any(const std::string& val) {
        /* OutputDebugStringA(val.c_str());
         OutputDebugStringA("\n");*/
        std::vector<any> vec;
        amo::u8json json(val);
        
        if (!json.is_array()) {
            return vec;
        }
        
        std::vector<amo::u8json> jsonArr = json.to_array();
        
        for (auto& p : jsonArr) {
            char type = p.get<char>("type");
            std::string val = p.get<std::string>("value");
            vec.push_back(amo::any(type, val));
        }
        
        return vec;
    }
    
    template<>   std::string any_to_string(const std::vector<any>& val) {
        amo::u8json jsonArr;
        jsonArr.set_array();
        
        for (auto p : val) {
            std::string str = p.to_string();
            /* OutputDebugStringA(str.c_str());
             OutputDebugStringA("\n");*/
            jsonArr.push_back(amo::u8json(str));
        }
        
        return jsonArr.to_string();
    }
    
}



#endif //AMO_ANY_VECTOR_8B50A677_D675_474A_B606_A4832AC1510F_HPP__